import {Read,Delete,Save, ReadOne} from './storeutil'
import { ReadDatasource } from './datasource'
const KEY = 'Sync'
export interface SyncItem{
    id:string,
    from:string,
    to:string,
    fromName:string,
    toName:string
}
export function ReadOneSync(id){
   return ReadOne(KEY,id)
}
export function ReadSync(){
    let arr = Read(KEY)
    let dsArr = ReadDatasource()
    let m = new Map();
    dsArr.forEach((v)=>{
        m.set(v.id,v)
    })
    let res = []
    arr.forEach((v)=>{
        let fd = m.get(v.from)
        v.fromName = fd?.name
        let td = m.get(v.to)
        v.toName = td?.name
        res.push(v)
    })
    return res
}
export function SaveSync(item){
    Save(KEY,item)
}
export function DeleteSync(id:string){
    Delete(KEY,id)
}
